package org.i1510.wuyo.service.impl;


	import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.i1510.common.bean.PageBean;
import org.i1510.common.service.impl.BaseServiceImpl;
import org.i1510.common.utils.BeanUtils;
import org.i1510.common.utils.DateUtils;
import org.i1510.common.utils.IDGenerator;
import org.i1510.common.utils.UserUtils;
import org.i1510.common.utils.web.ResultMapper;
import org.i1510.wuyo.dao.ISysUserLevelDao;
import org.i1510.wuyo.po.SysUserLevel;
import org.i1510.wuyo.service.ISysUserLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
	
	@Service("iSysUserLevelService")
	public class SysUserLevelServiceImpl extends BaseServiceImpl implements ISysUserLevelService{
		@Autowired
		private ISysUserLevelDao iSysUserLevelDao;	
		
		public ResultMapper save(SysUserLevel basePo,HttpServletRequest request) {
	
			ResultMapper mapper = ResultMapper.generateFailure();
			SysUserLevel saved = null;
			if(null !=basePo && basePo.getDocId() != null && !basePo.getDocId().equals("")){//修改
				SysUserLevel finder = iSysUserLevelDao.findById(basePo.getDocId());   
				if(null != finder){
					finder.setDocLastTime(DateUtils.getNow());
					finder.setDocLastor(UserUtils.getSessionUserBean(request).getSysUser().getDocId());			
				    BeanUtils.copy(finder, basePo);
				    saved = iSysUserLevelDao.save(finder);
				}else{
					mapper = ResultMapper.generateFailure();
					return mapper;
				}
				
			}else{//新增
				basePo.setDocId(IDGenerator.getGenerateID());
				basePo.setDocCreateTime(DateUtils.getNow());
				basePo.setDocCreator(UserUtils.getSessionUserBean(request).getSysUser().getDocId());
				saved = iSysUserLevelDao.save(basePo);
			}
	
			if (saved == null) {
				mapper = ResultMapper.generateFailure();
				return mapper;
			}else{
				mapper = ResultMapper.generateSuccess();
				return mapper;			
			}
		}
		public ResultMapper delete(String docId) {
	
			ResultMapper mapper = ResultMapper.generateFailure();
			iSysUserLevelDao.delete(docId);
			mapper = ResultMapper.generateSuccess();
			return mapper;
		}
	
		
		public SysUserLevel findById(String docId){
			return  iSysUserLevelDao.findById(docId);
		}
		
		public List<SysUserLevel> findByIds(List<String> docIds){
			return (List<SysUserLevel>) iSysUserLevelDao.findAll(docIds);
		}
		public List getPage(SysUserLevel sysUserLevel,PageBean pageBean,Map conditions) {
			Map map = new HashMap();
			//Bean转成Map
			BeanUtils.ObjectCopyMap(sysUserLevel, map);
			map.put("intPageIndex", pageBean.getIntPageIndex());
			map.put("intPageSize", pageBean.getIntPageSize());
			map.putAll(conditions);
			List list = this.queryForListBySql("sysUserLevelSql.getPage", map);
			return list;
		}
		public int getPageCount(SysUserLevel sysUserLevel,Map conditions) {
			Map map = new HashMap();
			//Bean转成Map
			BeanUtils.ObjectCopyMap(sysUserLevel, map);
			map.putAll(conditions);
			List list = this.queryForListBySql("sysUserLevelSql.getPageCount", map);		
			return list.size();
		}
	
	
}

